package com.dongdongshop.Controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.CategoryContentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("ConCategoryController")
@Controller
public class ConCategoryController {

    @Reference
    private CategoryContentService categoryContentService;

    @RequestMapping("toContentCatgory")
    public String toContentCatgory(){
        return "admin/content_category";
    }

    @RequestMapping("listCategory")
    @ResponseBody
    public Result listCategory(){
        List<TbContentCategory> list = categoryContentService.findAll();
        return Result.build(ConstantEnum.SUCCESS).setResult(list);
    }

    @RequestMapping("getUpdateCategory/{id}")
    @ResponseBody
    public Result getUpdateCategory(@PathVariable("id") Long id){
        TbContentCategory tbContentCategory = categoryContentService.selectById(id);
        return Result.build(ConstantEnum.SUCCESS).setResult(tbContentCategory);
    }
    @RequestMapping("updateCategory")
    @ResponseBody
    public Result updateCategory(TbContentCategory tbContentCategory){
        categoryContentService.updateById(tbContentCategory);
        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("insertCateGory")
    @ResponseBody
    public Result insertCateGory(TbContentCategory tbContentCategory){
        categoryContentService.insert(tbContentCategory);

        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("deleteAll")
    @ResponseBody
    public Result deleteAll(Long[] ids){
        categoryContentService.deleteAll(ids);
        return Result.build(ConstantEnum.SUCCESS);
    }
}
